package ooday04;

public class TestDemo {
    public static void main(String[] args) {

       /*
        //演示多态的第二点应用

        Master master=new Master();
        Dog dog=new Dog("小黑",2,"黑色");
        Fish fish=new Fish("小金",1,"金色");
        Chick chick=new Chick("",1,"");

        master.feed(dog);
        master.feed(fish);
        master.feed(chick);

        */




        //演示多态的第一点应用
        Animal1[] animal1s=new Animal1[5];
        animal1s[0]=new Dog("小黑",2,"黑色");
        animal1s[1]=new Dog("小白",3,"白色");
        animal1s[2]=new Fish("小花",1,"花色");
        animal1s[3]=new Fish("小金",2,"金色");
        animal1s[4]=new Chick("小黄",3,"黄色");

        for(int i=0;i<animal1s.length;i++){
            System.out.println(animal1s[i].name);
            animal1s[i].eat();
            animal1s[i].drink();

            if(animal1s[i] instanceof Dog){
                Dog dog=(Dog)animal1s[i];
                dog.look();
                dog.swim();
                Animal1 o=new Dog("小黑",25,"黑色");
                o.eat();
            }
            if(animal1s[i] instanceof Chick){
                Chick chick=(Chick)animal1s[i];
                chick.lay();
            }
            if (animal1s[i] instanceof Fish) {
                Fish fish=(Fish)animal1s[i];
                fish.swim();
            }

            /*

            //引用所指向的对象，就是该类型
            //引用所指向的对象，实现了该接口或继承了类
            Animal1 o=new Dog("小黑",1,"黑色");
            Dog g=(Dog) o;
            Swim s=(Dog)o;

            System.out.println(o instanceof Dog);
            System.out.println(o instanceof Swim);

             */




        }




        /*

        Dog[] dogs=new Dog[3];
            dogs[0]=new Dog("小黑",2,"黑");
            dogs[1]=new Dog("小白",1,"白");
            dogs[2]=new Dog("小灰",3,"灰");
            System.out.println(dogs[0].name);
            dogs[1].age=4;
            dogs[2].swim();
            for(int i=0;i< dogs.length;i++){
                System.out.println(dogs[i].name);
                dogs[i].eat();
                dogs[i].look();
            }

            Chick[] chicks=new Chick[2];
            chicks[0]=new Chick("大花",2,"橙");
            chicks[1]=new Chick("小花",1,"白");

            System.out.println(chicks[1].name);
            for(int j=0;j< chicks.length;j++){
                System.out.println(chicks[j].name);
                chicks[j].lay();
            }

            Fish[] fish=new Fish[2];
            fish[0]=new Fish("小金",1,"金色");
            fish[1]=new Fish("小黄",2,"黄色");
            System.out.println(fish[1].name);
            for(int k=0;k< fish.length;k++){
                System.out.println(fish[k].name);
            }


         */

        }
    }
